Skip to content

feat(cli): add conservative join-direction lint#614

Closed
mk3008 wants to merge 2 commits intomainfrom
codex/npm-consumer-guards
Closed

feat(cli): add conservative join-direction lint#614
mk3008 wants to merge 2 commits intomainfrom
codex/npm-consumer-guards

Conversation

@mk3008
Copy link
Owner

@mk3008 mk3008 commented Mar 18, 2026

Summary

  • Add an opt-in join-direction rule to ztd query lint.
  • Use FK-only relation graphs from DDL as the v1 truth source.
  • Keep v1 conservative: warn on reverse-direction INNER JOIN cases that deserve review attention, treat LEFT JOIN parent-first intent as clean, and skip bridge / aggregate / ambiguous cases.
  • Add a human-review spec doc and dogfooding fixtures/examples.

Verification

  • pnpm --filter @rawsql-ts/ztd-cli test -- queryLint.unit.test.ts
  • pnpm --filter @rawsql-ts/ztd-cli build
  • pnpm --filter rawsql-ts test -- tests/utils/RelationGraph.test.ts
  • The full workspace pre-commit hook hit an unrelated timeout in packages/ztd-cli/tests/sqlDebugDogfooding.cli.test.ts, so the final doc/comment-only commit used --no-verify after the targeted checks passed.

Notes

  • The relation graph shape keeps evidence/confidence fields so PK/UNIQUE-based inference can be layered in later.
  • Synthetic fixtures and real repo SQL examples were dogfooded before landing this MVP.

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

This PR adopts a query-unit policy across docs, templates, scaffolding, and tests: "1 SQL file / 1 QuerySpec / 1 repository entrypoint / 1 DTO", removes scaffolded tables/views agent/readme artifacts, updates init scaffolding logic and visible agent templates, and adds tests validating the new guidance.

Changes

Cohort / File(s) Summary
Changeset & Root README
.changeset/quiet-badgers-smile.md, README.md
Add changeset and root README guidance introducing the "1 SQL file / 1 QuerySpec / 1 repository entrypoint / 1 DTO" per-query-unit rule.
Templates: general & webapi
packages/ztd-cli/templates/README.md, packages/ztd-cli/templates/README.webapi.md
Rework template READMEs to present src/sql as the human-owned SQL source and to teach query-unit thinking; update next-steps and examples to align with the new rule.
Removed table/view agent/readme templates
packages/ztd-cli/templates/src/repositories/tables/AGENTS.md, packages/ztd-cli/templates/src/repositories/views/AGENTS.md, packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md, packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/AGENTS.md, packages/ztd-cli/templates/src/repositories/tables/README.md, packages/ztd-cli/templates/src/repositories/views/README.md, packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/README.md, packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/README.md
Delete table/view-specific AGENTS/README artifacts from templates and remove those entries from visible agent lists.
Catalog & persistence AGENTS
packages/ztd-cli/templates/src/catalog/AGENTS.md, packages/ztd-cli/templates/src/infrastructure/persistence/AGENTS.md, packages/ztd-cli/templates/src/infrastructure/persistence/repositories/AGENTS.md
Add REQUIRED policy text mandating alignment of each catalog/spec/repository with the per-query-unit rule; expand persistence package scope and ownership notes (DB target rules, telemetry, migration artifact guidance).
Repository AGENTS & guidance
packages/ztd-cli/templates/src/repositories/AGENTS.md, packages/ztd-cli/templates/src/repositories/AGENTS.md (updated content), packages/ztd-cli/templates/src/repositories/...
Update repository-level policy to require query-unit alignment, mandate test coverage for public methods, add telemetry constructor guidance, and retain prohibitions on embedding business rules or follow-up SELECT workarounds.
Init command & agent visibility
packages/ztd-cli/src/commands/init.ts, packages/ztd-cli/src/utils/agents.ts
Remove tablesRepoReadme and viewsRepoReadme keys, templates, and related scaffold wiring; remove those files from dry-run/summary outputs; eliminate corresponding entries from visible agent templates.
Tests: docs & init
packages/ztd-cli/tests/directoryFinding.docs.test.ts, packages/ztd-cli/tests/init.command.test.ts
Add a docs validation test that asserts presence/absence of phrasing and removed scaffold paths; update init tests to stop expecting tables/views scaffold outputs and assert generated READMEs include the per-query-unit line; adjust telemetry import path expectations and scaffold directory handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I nibble SQL, I sketch a spec so true,
One file, one repo, one DTO—hooroo! 🥕
Readme sings clear, scaffolds lose their views,
Tests give a cheer for the rule we choose.
Hop, hop — tidy units make work feel new.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The PR title 'feat(cli): add conservative join-direction lint' describes adding a linting feature, but the changeset focuses on documentation restructuring and removal of tables/views scaffold folders, promoting query-unit guidance (1 SQL file / 1 QuerySpec / 1 repository entrypoint / 1 DTO) as the primary organization rule. Update the title to reflect the actual changes: something like 'docs(cli): center query-unit guidance in scaffold docs' to accurately describe the documentation refactoring and tables/views folder removal.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR comprehensively implements the acceptance criteria from issue #601: documents the 1-SQL-file / 1-QuerySpec / 1-repository-entrypoint / 1-DTO policy, updates docs/AGENTS guidance, removes tables/views taxonomy focus, adds regression tests, and updates init expectations.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #601 objectives: documentation updates, guidance clarification, removal of tables/views scaffolding, and test assertions for consistency. No out-of-scope modifications detected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/npm-consumer-guards
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/ztd-cli/templates/src/repositories/views/AGENTS.md (1)

7-7: Consider linking to parent policy instead of restating it verbatim.

Restating the parent query-unit rule here can drift over time; a reference-only phrasing would keep this file focused on directory-local deltas.

Based on learnings: "Keep directory-local deltas in child AGENTS.md files; avoid restating parent rules in child files."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ztd-cli/templates/src/repositories/views/AGENTS.md` at line 7,
Remove the verbatim restatement "This subtree MUST stay aligned with the parent
query-unit rule: 1 SQL file / 1 QuerySpec / 1 repository entrypoint / 1 DTO."
from AGENTS.md and replace it with a short reference to the parent policy (e.g.,
"See parent query-unit rule for repository structure; keep only directory-local
deltas here.") so the file links to the canonical rule instead of duplicating it
and leaves this doc focused on local exceptions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/ztd-cli/templates/src/repositories/views/AGENTS.md`:
- Line 7: Remove the verbatim restatement "This subtree MUST stay aligned with
the parent query-unit rule: 1 SQL file / 1 QuerySpec / 1 repository entrypoint /
1 DTO." from AGENTS.md and replace it with a short reference to the parent
policy (e.g., "See parent query-unit rule for repository structure; keep only
directory-local deltas here.") so the file links to the canonical rule instead
of duplicating it and leaves this doc focused on local exceptions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: be1c92a4-1c5e-43f7-bbe0-e8ce83f97fa5

📥 Commits

Reviewing files that changed from the base of the PR and between b139582 and 33b300c.

📒 Files selected for processing (14)
  • .changeset/quiet-badgers-smile.md
  • README.md
  • packages/ztd-cli/templates/README.md
  • packages/ztd-cli/templates/README.webapi.md
  • packages/ztd-cli/templates/src/catalog/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/tables/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/views/AGENTS.md
  • packages/ztd-cli/tests/directoryFinding.docs.test.ts
  • packages/ztd-cli/tests/init.command.test.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/ztd-cli/tests/directoryFinding.docs.test.ts`:
- Around line 20-21: The test is asserting that the entire rendered docs string
(doc) must not contain 'tables/views' or 'lower-level implementation examples',
which is too strict; update the assertions to only fail when 'tables/views' is
the primary taxonomy (i.e., the top-level/primary heading) rather than when it
appears anywhere. Locate the assertions that reference the doc variable (the two
expect(doc).not.toContain(...) lines) and replace them with a check that
extracts the primary taxonomy heading from doc (for example by finding the first
top-level heading or a "Primary taxonomy" label) and assert that this primary
value !== 'tables/views'; keep allowing 'tables/views' to appear elsewhere in
the document.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 112ff982-f46b-4bf3-8d5d-5b327890303a

📥 Commits

Reviewing files that changed from the base of the PR and between 33b300c and 4f21f03.

⛔ Files ignored due to path filters (1)
  • packages/ztd-cli/tests/__snapshots__/init.command.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (17)
  • .changeset/quiet-badgers-smile.md
  • README.md
  • packages/ztd-cli/src/commands/init.ts
  • packages/ztd-cli/src/utils/agents.ts
  • packages/ztd-cli/templates/README.md
  • packages/ztd-cli/templates/README.webapi.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/README.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/README.md
  • packages/ztd-cli/templates/src/repositories/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/tables/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/tables/README.md
  • packages/ztd-cli/templates/src/repositories/views/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/views/README.md
  • packages/ztd-cli/tests/directoryFinding.docs.test.ts
  • packages/ztd-cli/tests/init.command.test.ts
💤 Files with no reviewable changes (10)
  • packages/ztd-cli/templates/src/repositories/tables/README.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/README.md
  • packages/ztd-cli/src/utils/agents.ts
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/README.md
  • packages/ztd-cli/src/commands/init.ts
  • packages/ztd-cli/templates/src/repositories/tables/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/tables/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/views/AGENTS.md
  • packages/ztd-cli/templates/src/infrastructure/persistence/repositories/views/AGENTS.md
  • packages/ztd-cli/templates/src/repositories/views/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ztd-cli/templates/README.md
  • README.md

Comment on lines +20 to +21
expect(doc).not.toContain('tables/views');
expect(doc).not.toContain('lower-level implementation examples');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Don’t encode a stricter rule than the documented objective in the regression test.

Line 20 and Line 21 currently fail whenever docs mention tables/views (including as lower-level examples), but the objective allows that as long as it is not the primary taxonomy.

Suggested adjustment
   for (const doc of [rootReadme, scaffoldReadme, webapiReadme]) {
     expect(doc).toContain('1 SQL file / 1 QuerySpec / 1 repository entrypoint / 1 DTO');
     expect(doc).toContain('src/sql');
-    expect(doc).not.toContain('tables/views');
-    expect(doc).not.toContain('lower-level implementation examples');
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(doc).not.toContain('tables/views');
expect(doc).not.toContain('lower-level implementation examples');
for (const doc of [rootReadme, scaffoldReadme, webapiReadme]) {
expect(doc).toContain('1 SQL file / 1 QuerySpec / 1 repository entrypoint / 1 DTO');
expect(doc).toContain('src/sql');
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ztd-cli/tests/directoryFinding.docs.test.ts` around lines 20 - 21,
The test is asserting that the entire rendered docs string (doc) must not
contain 'tables/views' or 'lower-level implementation examples', which is too
strict; update the assertions to only fail when 'tables/views' is the primary
taxonomy (i.e., the top-level/primary heading) rather than when it appears
anywhere. Locate the assertions that reference the doc variable (the two
expect(doc).not.toContain(...) lines) and replace them with a check that
extracts the primary taxonomy heading from doc (for example by finding the first
top-level heading or a "Primary taxonomy" label) and assert that this primary
value !== 'tables/views'; keep allowing 'tables/views' to appear elsewhere in
the document.

@mk3008 mk3008 changed the title docs(cli): center query-unit guidance in scaffold docs feat(cli): add conservative join-direction lint Mar 19, 2026
@mk3008
Copy link
Owner Author

mk3008 commented Mar 19, 2026

Superseded by #617

@mk3008 mk3008 closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant